package com.xinqizhi.controller;


import com.xinqizhi.entity.SysDict;
import com.xinqizhi.service.impl.SysDictServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**  
 * @ClassName: SysDictController  
 * @Description: ${todo}(控制器)  
 * @author yangtongquan  
 * @date 2019-07-08  
 *  
 */
@Controller
@RequestMapping("/dict")
public class SysDictController   {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private SysDictServiceImpl  sysDictService;


	/**
	* 分页查询数据列表
	* @param sysDict
	* @return
	*/
	@RequestMapping("/list")
    @ResponseBody
	public Map getList(SysDict sysDict) {
	Map<String, Object> result = new HashMap<>(16);
        Map<String, List> listMap = sysDictService.dictList2HashByTypeName();
        //PageInfo page = new PageInfo(sysDictList);
		//result.put("count", page.getTotal());
		result.put("data",listMap);
		/*try {
			String filterName = sysDict.getFiltername();
			if (sysDict.getPaging()){
			PageHelper.startPage(sysDict.getPage(),sysDict.getLimit());
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}*/
		return result;
	}

   /* *//**
    * 插入一条数据
    * @param sysDict
    * @return
    *//*
    @RequestMapping("add")
    public Map add(SysDict sysDict) {
    Map<String, Object> result = new HashMap<>(16);
    result.put("success", false);
		try {
	        sysDict.setCreateTime(new Timestamp(System.currentTimeMillis()));
	        sysDict.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			int flag =  sysDictService.insertSelectData(sysDict);
			result = CommonUtils.getUpdateAndAddResult(result, flag == 1, METHOD_TYPE.ADD);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result = CommonUtils.getErrorResult(result, e, METHOD_TYPE.ADD);
		}
		return result;
    }

    *//**
    * 更新数据
    * @param sysDict
    * @return
    *//*
    @RequestMapping("update")
    public Map update(SysDict sysDict) {
    Map<String, Object> result = new HashMap<>(16);
    result.put("success", false);
		try {
	        sysDict.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			int flag = sysDictService.updateData(sysDict);
			result = CommonUtils.getUpdateAndAddResult(result, flag > 0, METHOD_TYPE.UPDATE);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result = CommonUtils.getErrorResult(result, e, METHOD_TYPE.UPDATE);
		}
		return result;
    }


    *//**
    * 删除数据
    * @param dicId
    * @return
    *//*
    @RequestMapping("delete")
    public Map delete(Integer dicId){
    Map<String, Object> result = new HashMap<>(16);
    result.put("success", false);
		try {
			int flag = sysDictService.deleteData(dicId);
			result = CommonUtils.getUpdateAndAddResult(result, flag > 0, METHOD_TYPE.DELETE);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result = CommonUtils.getErrorResult(result, e, METHOD_TYPE.DELETE);
		}
		return result;
    }

    *//**
    * 批量删除
    * @param ids
    * @return
    *//*
    @RequestMapping("batchDelete")
    public Map batchDelete(String ids){
    Map<String, Object> result = new HashMap<>(16);
    result.put("success", false);
		try {
			int flag = sysDictService.deleteBatchData(ids.split(","));
			result = CommonUtils.getUpdateAndAddResult(result, flag > 0, METHOD_TYPE.BATCH_DEL);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result = CommonUtils.getErrorResult(result, e, METHOD_TYPE.BATCH_DEL);
		}
		return result;
    }*/
}
